package me.lc;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources.NotFoundException;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;

import com.admogo.AdMogoLayout;
import com.admogo.AdMogoListener;
import com.admogo.AdMogoManager;
import com.mobclick.android.MobclickAgent;

public class FunPeaceActivity extends Activity implements OnGestureListener,
		AdMogoListener {

	private boolean isLoaded = false;
	private ProgressDialog progressDialog;
	private int delaySeconds = 0;
	private int countDown = 0;
	private View page1;
	private View page2;
	private View page3;
	private View page4;
	private Button btnWigame;
	private Button btnWisocial;
	private Button btnHimarket;
	private ViewFlipper vf;
	private GestureDetector gd;
	private int pageIndex = 0;
	private PageControlView pageControler;
	private SharedPreferences settings;
	private LinearLayout adLayout;
	private CheckBox chkSetNotification;
	private int piCount = 0;
	private int delayPiCount = 0;
	private int prePiCount = 0;
	private int preDelayPiCount = 0;
	String isMoneyOn;
	String openAD;

	private static String piCountKey = "piCount";
	private static String delayPiCountKey = "piCount";

	String status;
	String status2;

	public static SharedPreferences sharedPreferences;
	public static FunPeaceActivity Instance;

	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	@Override
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	@Override
	protected void onDestroy() {
		AdMogoManager.clear();
		super.onDestroy();
	}

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Instance = this;
		MobclickAgent.onError(this);
		MobclickAgent.updateOnlineConfig(this);
		SoundManager.instance.setContext(this);
		AppControl.init();
		settings = this.getPreferences(Activity.MODE_PRIVATE);
		if (!isLoaded) {
			// WiGame.init(this, "042ba29125570702",
			// "Pcj7KqgvWBGBnKLHaLucWDkpXhq6EZC4", "1.0", false);

			animation_right_in = AnimationUtils.loadAnimation(this,
					R.anim.animation_right_in);
			animation_left_out = AnimationUtils.loadAnimation(this,
					R.anim.animation_left_out);
			animation_left_in = AnimationUtils.loadAnimation(this,
					R.anim.animation_left_in);
			animation_right_out = AnimationUtils.loadAnimation(this,
					R.anim.animation_right_out);

			status = settings.getString("lockStatus", "");
			status2 = settings.getString("lockStatus2", "");

			setUI();
			Timer countDownTimer = new Timer();
			countDownTimer.schedule(new CountDownTask(), 1000, 1000);

			Timer uploadScoreTimer = new Timer();
			uploadScoreTimer.schedule(new UploadScoreTask(), 5000, 15000);
			isLoaded = true;

		}
	}

	public synchronized void initNewPage() {
		isMoneyOn = "false";
		openAD = isMoneyOn;
		if (AppControl.isShowAd()) {
			isMoneyOn = "true";
			openAD = isMoneyOn;
		}

		// TODO 广告商审核用
		// openAD = "true";
		// isMoneyOn = "false";
		// isMoneyOn = "true";

		setPageLock();

		boolean isfirst = settings.getBoolean("isfirst33", true);
		if (isfirst) {
			dialog("新功能！", "新增将放屁声音设置到短信铃声功能，相信大家能将此功能发扬光大！");
			Editor editor = settings.edit();
			editor.putBoolean("isfirst33", false);
			editor.commit();
		}

		setAD();
	}

	public void setPageLock() {
		if (status.length() > 0 || isMoneyOn.equalsIgnoreCase("false")) {
			((TextView) page3.findViewById(R.id.textViewLock))
					.setVisibility(View.GONE);
			((ImageView) page3.findViewById(R.id.imageViewLock))
					.setVisibility(View.GONE);
			((TableLayout) page3.findViewById(R.id.buttonTablePage3))
					.setVisibility(View.VISIBLE);
		} else {
			((TextView) page3.findViewById(R.id.textViewLock))
					.setVisibility(View.VISIBLE);
			((ImageView) page3.findViewById(R.id.imageViewLock))
					.setVisibility(View.VISIBLE);
			((TableLayout) page3.findViewById(R.id.buttonTablePage3))
					.setVisibility(View.GONE);
		}

		if (status2.length() > 0 || isMoneyOn.equalsIgnoreCase("false")) {
			((TextView) page4.findViewById(R.id.textViewLock4))
					.setVisibility(View.GONE);
			((ImageView) page4.findViewById(R.id.imageViewLock4))
					.setVisibility(View.GONE);
			((TableLayout) page4.findViewById(R.id.buttonTablePage4))
					.setVisibility(View.VISIBLE);
		} else {
			((TextView) page4.findViewById(R.id.textViewLock4))
					.setVisibility(View.VISIBLE);
			((ImageView) page4.findViewById(R.id.imageViewLock4))
					.setVisibility(View.VISIBLE);
			((TableLayout) page4.findViewById(R.id.buttonTablePage4))
					.setVisibility(View.GONE);
		}
	}

	// 广告是否已经显示
	private boolean isAdShowed = false;

	private synchronized void setAD() {
		// 是否出广告
		if (!openAD.equals("false") && !isAdShowed) {
			isAdShowed = true;
			AdMogoLayout adMogoLayoutCode = new AdMogoLayout(this,
					"e1ff77306cdf4a568e97d74cc3792b78");
			adMogoLayoutCode.setAdMogoListener(this);
			FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
					FrameLayout.LayoutParams.FILL_PARENT,
					FrameLayout.LayoutParams.WRAP_CONTENT);

			adLayout = (LinearLayout) findViewById(R.id.admogo_layout);
			adLayout.addView(adMogoLayoutCode, params);
		}
	}

	public void dialog(String title, final String message) {
		AlertDialog.Builder builder = new Builder(this);
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton("知道了", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		});
		builder.create().show();
	}

	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				countDown--;
				if (countDown >= 0) {
					if (progressDialog != null) {
						progressDialog.setProgress(countDown);
						progressDialog.setMessage("剩余" + countDown + "秒");
					}
				}
				break;
			}
		}
	};

	class CountDownTask extends TimerTask {
		@Override
		public void run() {
			Message msg = new Message();
			msg.what = 1;
			handler.sendMessage(msg);
		}
	}

	boolean canActiveAdClick = true;

	class UploadScoreTask extends TimerTask {
		@Override
		public void run() {
			System.out.println("UploadScoreTask");
			canActiveAdClick = true;
			// boolean sumChanged = false;
			// if (preDelayPiCount < delayPiCount) {
			// System.out.println("Upload delayPiCount:" + delayPiCount);
			// sumChanged = true;
			// // WiGame.submitScore("436facc1fde087e8", delayPiCount, null,
			// // true);
			// preDelayPiCount = delayPiCount;
			// }
			// if (prePiCount < piCount) {
			// System.out.println("Upload piCount:" + piCount);
			// sumChanged = true;
			// // WiGame.submitScore("627b3ce32d88642a", piCount, null, true);
			// prePiCount = piCount;
			// }
			// if (sumChanged) {
			// int sum = piCount + delayPiCount;
			// if (sum >= 10000) {
			// // WiGame.unlockAchievement("3750e1e79c93dbc7");
			// } else if (sum >= 2000) {
			// // WiGame.unlockAchievement("6e7cf6ab6a87351b");
			// } else if (sum >= 200) {
			// // WiGame.unlockAchievement("f1affa497b3005f3");
			// } else if (sum >= 100) {
			// // WiGame.unlockAchievement("2a5c64791ea97622");
			// } else if (sum >= 20) {
			// // WiGame.unlockAchievement("d94f37ea7a802c61");
			// } else if (sum >= 10) {
			// // WiGame.unlockAchievement("e7cfd3c69f1301fc");
			// } else if (sum >= 2) {
			// // WiGame.unlockAchievement("f9fe3513a1cacf12");
			// }
			// }
		}
	}

	class PlaySountTask extends TimerTask {
		private int soundId = 0;
		private boolean isDelay = false;

		public PlaySountTask(int soundId, boolean isDelay) {
			this.soundId = soundId;
			this.isDelay = isDelay;
		}

		@Override
		public void run() {
			if (progressDialog != null) {
				progressDialog.cancel();
			}
			SoundManager.instance.playSound(soundId);
			// 更新统计, 大于一半声音以上才能算
			if (SoundManager.instance.getVolume() >= 0.5f) {
				if (!isDelay) {

					piCount++;
					if (piCount > 0) {
						ShareSettingUtil.storeIntSetting(piCountKey, piCount,
								settings);
					}

				} else {
					delayPiCount++;
					if (delayPiCount > 0) {
						ShareSettingUtil.storeIntSetting(delayPiCountKey,
								delayPiCount, settings);
					}
				}
			}

		}
	}

	private void setUI() {
		OnClickListener lis = new OnClickListener() {
			@Override
			public void onClick(View v) {
				int soundIndex = 0;
				switch (v.getId()) {
				case R.id.button1:
					soundIndex = 0;
					break;
				case R.id.button2:
					soundIndex = 1;
					break;
				case R.id.button3:
					soundIndex = 2;
					break;
				case R.id.button4:
					soundIndex = 3;
					break;
				case R.id.button5:
					soundIndex = 4;
					break;
				case R.id.button6:
					soundIndex = 5;
					break;
				case R.id.button7:
					soundIndex = 6;
					break;
				case R.id.button8:
					soundIndex = 7;
					break;
				case R.id.button9:
					soundIndex = 8;
					break;
				case R.id.button10:
					soundIndex = 9;
					break;
				case R.id.button11:
					soundIndex = 10;
					break;
				case R.id.button12:
					soundIndex = 11;
					break;
				case R.id.button13:
					soundIndex = 12;
					break;
				case R.id.button14:
					soundIndex = 13;
					break;
				case R.id.button15:
					soundIndex = 14;
					break;
				case R.id.button16:
					soundIndex = 15;
					break;
				case R.id.button17:
					soundIndex = 16;
					break;
				case R.id.button18:
					soundIndex = 17;
					break;
				case R.id.button19:
					soundIndex = 18;
					break;
				case R.id.button20:
					soundIndex = 19;
					break;
				case R.id.button21:
					soundIndex = 20;
					break;
				case R.id.button22:
					soundIndex = 21;
					break;
				case R.id.button23:
					soundIndex = 22;
					break;
				case R.id.button24:
					soundIndex = 23;
					break;
				case R.id.button25:
					soundIndex = 24;
					break;
				case R.id.button26:
					soundIndex = 25;
					break;
				case R.id.button27:
					soundIndex = 26;
					break;
				case R.id.button28:
					soundIndex = 27;
					break;
				case R.id.button29:
					soundIndex = 28;
					break;
				case R.id.button30:
					soundIndex = 29;
					break;

				case R.id.button31:
					soundIndex = 30;
					break;
				case R.id.button32:
					soundIndex = 31;
					break;
				case R.id.button33:
					soundIndex = 32;
					break;
				case R.id.button34:
					soundIndex = 33;
					break;
				case R.id.button35:
					soundIndex = 34;
					break;
				case R.id.button36:
					soundIndex = 35;
					break;
				case R.id.button37:
					soundIndex = 36;
					break;
				case R.id.button38:
					soundIndex = 37;
					break;
				case R.id.button39:
					soundIndex = 38;
					break;
				case R.id.button40:
					soundIndex = 39;
					break;
				default:
					soundIndex = -1;
					break;
				}
				if (chkSetNotification.isChecked()) {
					// 设置短信铃声
					SetNotificationHelper.setNotification(soundIndex);
				} else {
					Button currentBtn = (Button) v;
					String piName = currentBtn.getText().toString();
					if (soundIndex >= 0) {
						boolean isDelay = delaySeconds > 0;
						Timer timer = new Timer();
						timer.schedule(new PlaySountTask(soundIndex, isDelay),
								1000 * delaySeconds);
						if (delaySeconds > 0) {
							progressDialog = new ProgressDialog(
									FunPeaceActivity.this);
							progressDialog
									.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
							progressDialog.setTitle("放屁倒计时（" + piName + "）");
							progressDialog.setIcon(R.drawable.icon);
							progressDialog
									.setMessage("剩余" + delaySeconds + "秒");
							progressDialog.setCancelable(false);
							progressDialog.setMax(delaySeconds);
							progressDialog.setProgress(delaySeconds);
							progressDialog.show();
							countDown = delaySeconds;
						} else {
							progressDialog = null;
						}
					}
				}
			}
		};

		FriendlyScrollView sv = (FriendlyScrollView) this
				.findViewById(R.id.friendlyScrollView);
		page1 = this.getLayoutInflater().inflate(R.layout.page1, null);
		page2 = this.getLayoutInflater().inflate(R.layout.page2, null);
		page3 = this.getLayoutInflater().inflate(R.layout.page3, null);
		page4 = this.getLayoutInflater().inflate(R.layout.page4, null);
		page1.setLongClickable(true);
		page2.setLongClickable(true);
		page3.setLongClickable(true);
		page4.setLongClickable(true);
		gd = new GestureDetector(this);
		sv.setGestureDetector(gd);
		pageControler = (PageControlView) this.findViewById(R.id.pageControl);
		vf = (ViewFlipper) this.findViewById(R.id.myViewflipper);
		vf.addView(page1, 0);
		vf.addView(page2, 1);
		vf.addView(page3, 2);
		vf.addView(page4, 3);
		Button btn1 = (Button) page1.findViewById(R.id.button1);
		Button btn2 = (Button) page1.findViewById(R.id.button2);
		Button btn3 = (Button) page2.findViewById(R.id.button3);
		Button btn4 = (Button) page2.findViewById(R.id.button4);
		Button btn5 = (Button) page1.findViewById(R.id.button5);
		Button btn6 = (Button) page1.findViewById(R.id.button6);
		Button btn7 = (Button) page2.findViewById(R.id.button7);
		Button btn8 = (Button) page2.findViewById(R.id.button8);
		Button btn9 = (Button) page1.findViewById(R.id.button9);
		Button btn10 = (Button) page1.findViewById(R.id.button10);
		Button btn11 = (Button) page2.findViewById(R.id.button11);
		Button btn12 = (Button) page2.findViewById(R.id.button12);
		Button btn13 = (Button) page1.findViewById(R.id.button13);
		Button btn14 = (Button) page1.findViewById(R.id.button14);
		Button btn15 = (Button) page2.findViewById(R.id.button15);
		Button btn16 = (Button) page2.findViewById(R.id.button16);
		Button btn17 = (Button) page1.findViewById(R.id.button17);
		Button btn18 = (Button) page1.findViewById(R.id.button18);
		Button btn19 = (Button) page2.findViewById(R.id.button19);
		Button btn20 = (Button) page2.findViewById(R.id.button20);

		Button btn21 = (Button) page3.findViewById(R.id.button21);
		Button btn22 = (Button) page3.findViewById(R.id.button22);
		Button btn23 = (Button) page3.findViewById(R.id.button23);
		Button btn24 = (Button) page3.findViewById(R.id.button24);
		Button btn25 = (Button) page3.findViewById(R.id.button25);
		Button btn26 = (Button) page3.findViewById(R.id.button26);
		Button btn27 = (Button) page3.findViewById(R.id.button27);
		Button btn28 = (Button) page3.findViewById(R.id.button28);
		Button btn29 = (Button) page3.findViewById(R.id.button29);
		Button btn30 = (Button) page3.findViewById(R.id.button30);

		Button btn31 = (Button) page4.findViewById(R.id.button31);
		Button btn32 = (Button) page4.findViewById(R.id.button32);
		Button btn33 = (Button) page4.findViewById(R.id.button33);
		Button btn34 = (Button) page4.findViewById(R.id.button34);
		Button btn35 = (Button) page4.findViewById(R.id.button35);
		Button btn36 = (Button) page4.findViewById(R.id.button36);
		Button btn37 = (Button) page4.findViewById(R.id.button37);
		Button btn38 = (Button) page4.findViewById(R.id.button38);
		Button btn39 = (Button) page4.findViewById(R.id.button39);
		Button btn40 = (Button) page4.findViewById(R.id.button40);

		btn1.setOnClickListener(lis);
		btn2.setOnClickListener(lis);
		btn3.setOnClickListener(lis);
		btn4.setOnClickListener(lis);
		btn5.setOnClickListener(lis);
		btn6.setOnClickListener(lis);
		btn7.setOnClickListener(lis);
		btn8.setOnClickListener(lis);
		btn9.setOnClickListener(lis);
		btn10.setOnClickListener(lis);
		btn11.setOnClickListener(lis);
		btn12.setOnClickListener(lis);
		btn13.setOnClickListener(lis);
		btn14.setOnClickListener(lis);
		btn15.setOnClickListener(lis);
		btn16.setOnClickListener(lis);
		btn17.setOnClickListener(lis);
		btn18.setOnClickListener(lis);
		btn19.setOnClickListener(lis);
		btn20.setOnClickListener(lis);
		btn21.setOnClickListener(lis);
		btn22.setOnClickListener(lis);
		btn23.setOnClickListener(lis);
		btn24.setOnClickListener(lis);
		btn25.setOnClickListener(lis);
		btn26.setOnClickListener(lis);
		btn27.setOnClickListener(lis);
		btn28.setOnClickListener(lis);
		btn29.setOnClickListener(lis);
		btn30.setOnClickListener(lis);
		btn31.setOnClickListener(lis);
		btn32.setOnClickListener(lis);
		btn33.setOnClickListener(lis);
		btn34.setOnClickListener(lis);
		btn35.setOnClickListener(lis);
		btn36.setOnClickListener(lis);
		btn37.setOnClickListener(lis);
		btn38.setOnClickListener(lis);
		btn39.setOnClickListener(lis);
		btn40.setOnClickListener(lis);

		SeekBar secondBar = (SeekBar) findViewById(R.id.seekBarSecond);
		secondBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				TextView txtNote = (TextView) findViewById(R.id.txtTime);
				txtNote.setText("放屁延时：" + progress + "秒");
				delaySeconds = progress;
			}
		});

		SeekBar volumeBar = (SeekBar) findViewById(R.id.seekBarVolume);
		volumeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
			}

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress,
					boolean fromUser) {
				SoundManager.instance.setVolume((float) (progress / 100.0));
			}
		});
		volumeBar.setProgress((int) (SoundManager.instance.getVolume() * 100));
		pageControler.setCount(4);
		pageControler.generatePageControl(0);
		pageControler.postInvalidate();
		initNewPage();

		// wigame
		// btnWigame = (Button) findViewById(R.id.btnWiGame);
		// btnWigame.setOnClickListener(new OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// // 直接打开排行榜
		// WiGame.openLeaderboards();
		// }
		// });
		//
		// btnWisocial = (Button) findViewById(R.id.btnWiSocial);
		// btnWisocial.setOnClickListener(new OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// WiGame.openDiscussion();
		// }
		// });

		// 设置checkbox实例
		chkSetNotification = (CheckBox) findViewById(R.id.chkSetNotification);

		// TODO 首发用的
		// btnHimarket = (Button) findViewById(R.id.btnHimarket);
		// btnHimarket.setOnClickListener(new OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// Uri uri = Uri
		// .parse("http://sc.hiapk.com/Download.aspx?aid=51&sc=1");
		// Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		// FunPeaceActivity.this.startActivity(intent);
		// }
		// });

		piCount = ShareSettingUtil.getIntSetting(piCountKey, 0, settings);
		delayPiCount = ShareSettingUtil.getIntSetting(delayPiCountKey, 0,
				settings);
		preDelayPiCount = delayPiCount;
		prePiCount = piCount;
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		return gd.onTouchEvent(event);
	}

	@Override
	public boolean onDown(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

	Animation animation_right_in;
	Animation animation_left_out;
	Animation animation_left_in;
	Animation animation_right_out;

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		try {
			if ((e1.getX() - e2.getX()) > 100) {
				this.vf.setInAnimation(animation_right_in);
				this.vf.setOutAnimation(animation_left_out);
				this.vf.showNext();
				pageIndex++;
				pageIndex = pageIndex % 4;
				pageControler.generatePageControl(pageIndex);
				pageControler.postInvalidate();
				return true;
			} else if ((e1.getX() - e2.getX()) < -100) {
				this.vf.setInAnimation(animation_left_in);
				this.vf.setOutAnimation(animation_right_out);
				this.vf.showPrevious();

				if (pageIndex == 0) {
					pageIndex = 3;
				} else {
					pageIndex--;
				}
				pageControler.generatePageControl(pageIndex);
				pageControler.postInvalidate();
				return true;
			}
		} catch (NotFoundException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void onShowPress(MotionEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

	// @Override
	// public boolean onTouch(View v, MotionEvent event) {
	// return gd.onTouchEvent(event);
	// }

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
			showExitTips();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	public void showExitTips() {
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				AlertDialog alertDialog = new AlertDialog.Builder(
						FunPeaceActivity.this)
						.setTitle("退出")
						.setMessage("是否退出放屁精灵")
						.setPositiveButton("确定",
								new DialogInterface.OnClickListener() {
									public void onClick(DialogInterface dialog,
											int which) {
										// TODO 广告商审核时去掉
										// 酷果
										// System.out.println("kuguo");
										// PushAdsManager paManager =
										// PushAdsManager
										// .getInstance();
										// paManager
										// .setCooId(
										// FunPeaceActivity.Instance,
										// "453870919bb34771a834d9cb1b732ca6");
										// paManager
										// .receivePushMessage(
										// FunPeaceActivity.Instance,
										// true);
										FunPeaceActivity.this.finish();
									}
								})
						.setNegativeButton("取消",
								new DialogInterface.OnClickListener() {
									public void onClick(DialogInterface dialog,
											int which) {
										return;
									}
								}).setCancelable(false).create(); // 创建对话框
				alertDialog.show();
			}
		});
	}

	@Override
	public synchronized void onClickAd() {
		System.out.println("广告click");

		if (canActiveAdClick) {
			canActiveAdClick = false;
			// unlock
			if (!isMoneyOn.equalsIgnoreCase("false")) {
				if (settings.getString("lockStatus", "").length() == 0) {
					Editor editor = settings.edit();
					editor.putString("lockStatus", "unlock");
					editor.commit();
					status = "unlock";
					setPageLock();
				} else {
					Editor editor = settings.edit();
					editor.putString("lockStatus2", "unlock");
					editor.commit();
					status2 = "unlock";
					setPageLock();
				}
			}
		}

	}

	@Override
	public void onCloseAd() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onCloseMogoDialog() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onFailedReceiveAd() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onRealClickAd() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onReceiveAd() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onRequestAd() {
		// TODO Auto-generated method stub

	}

}